CHARTS
Photo by Nathan Dumlao on Unsplash
Don’t call the world dirty because you forgot to clean your glasses…
— Aaron Hill
# Load data
df = read.csv("archetypes/family-policy-scores-by-country/family-policy-scores-by-country.csv", header = TRUE, stringsAsFactors = TRUE)
df
theme_opts <- theme(
plot.margin = margin(.25, 1, .25, .25, "cm"),
plot.background = element_blank(),
panel.background = element_blank(),
legend.position = "none",
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.ticks.y=element_blank(),
axis.ticks.x=element_blank(),
axis.text.x=element_blank(),
strip.placement = "outside", # Place facet labels outside x axis labels.
strip.background = element_rect(fill = "white"), # Make facet label background white.
axis.title = element_blank() # Remove x and y axis titles.
)
# Make the plot
v1 <- ggplot(df, aes(x=Family.Integration.Policy.Average.Scores, y=Country)) +
geom_bar(stat="identity", fill="#88b88a") +
# scale_y_discrete(limits=c("Almond milk", "Oat milk", "Soy milk", "Rice milk","Cow's milk")) +
#scale_fill_manual(values=c("Carbon Emissions (kg CO2eq)" = "#364e5d", "Land Use (m2)" = "#597e4e", "Water Use (L)" = "#587f89")) +
#scale_color_manual(values=c("white" = "#ffffff", "black" = "#000000")) +
coord_cartesian(clip="off") +
labs(title = "FAMILY INTEGRATION POLICY AVERAGE SCORES BY COUNTRY, 2014") +
theme_opts
# Print the plot
girafe(ggobj = v1, width_svg = 720/72, height_svg = 1280/72,
options = list(opts_sizing(rescale = TRUE, width = 1.0)))
# Make the plot
v2 <- ggplot(df, aes(x=Family.Integration.Policy.Average.Scores, y=reorder(Country,Family.Integration.Policy.Average.Scores))) +
geom_bar(stat="identity", fill="#88b88a") +
# scale_y_discrete(limits=c("Almond milk", "Oat milk", "Soy milk", "Rice milk","Cow's milk")) +
#scale_fill_manual(values=c("Carbon Emissions (kg CO2eq)" = "#364e5d", "Land Use (m2)" = "#597e4e", "Water Use (L)" = "#587f89")) +
#scale_color_manual(values=c("white" = "#ffffff", "black" = "#000000")) +
coord_cartesian(clip="off") +
labs(title = "FAMILY INTEGRATION POLICY AVERAGE SCORES BY COUNTRY, 2014") +
theme_opts
# Print the plot
girafe(ggobj = v2, width_svg = 720/72, height_svg = 1280/72,
options = list(opts_sizing(rescale = TRUE, width = 1.0)))
# Make the plot
v3 <- ggplot(df, aes(x=Family.Integration.Policy.Average.Scores, y=reorder(Country,-Family.Integration.Policy.Average.Scores))) +
geom_bar(stat="identity", fill="#88b88a") +
# scale_y_discrete(limits=c("Almond milk", "Oat milk", "Soy milk", "Rice milk","Cow's milk")) +
#scale_fill_manual(values=c("Carbon Emissions (kg CO2eq)" = "#364e5d", "Land Use (m2)" = "#597e4e", "Water Use (L)" = "#587f89")) +
#scale_color_manual(values=c("white" = "#ffffff", "black" = "#000000")) +
coord_cartesian(clip="off") +
labs(title = "FAMILY INTEGRATION POLICY AVERAGE SCORES BY COUNTRY, 2014") +
theme_opts
# Print the plot
girafe(ggobj = v3, width_svg = 720/72, height_svg = 1280/72,
options = list(opts_sizing(rescale = TRUE, width = 1.0)))
# As reusable function
make_hbar <- function(df, x_field, y_field, fill_str, title_str) {
x_var <- c(x_field)
y_var <- c(y_field)
ggplot(df, aes(x=get(x_var), y=get(y_var))) +
geom_bar(stat="identity", fill=fill_str) +
coord_cartesian(clip="off") +
labs(title = title_str) +
theme_opts
}